package com.nuonuo.util;

import java.util.Calendar;
import java.util.Date;

/**
 * @author duan
 * @version 1.0
 * @date 2023/10/25 15:56
 */
public class DateUtil {


    public static Date offsetSecond(Date date, Integer offset) {
        return offset(date, Calendar.SECOND, offset);
    }

    /**
     * 获取根据偏移单位偏移后的时间
     *
     * @param date 时间
     * @param dateFiled 偏移单位
     * @param offset 偏移量
     * @return Date
     */
    public static Date offset(Date date, int dateFiled, int offset) {
        Calendar calendar = toCalendar(date);
        calendar.add(dateFiled, offset);
        return calendar.getTime();
    }

    public static Calendar toCalendar(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }
}
